package com.qr.service.wmyw.impl;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.mapping.ResultMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.krui.helper.db.DBHelper;
import cn.krui.helper.db.DataPage;
import com.qr.bean.wmyw.QrGoodsGroup;
import com.qr.bean.wmyw.QrGoodsGroupView;
import com.qr.controller.WmywBase;
import com.qr.mapper.wmyw.QrGoodsGroupMapper;
import com.qr.mapper.wmyw.QrGoodsGroupMapperView;
import com.qr.service.wmyw.QrGoodsGroupService;
//import org.apache.dubbo.config.annotation.Service;

/**
 * @author: zc
 * email: zc8023zs@163.com
 * create_time: 2020/8/13 10:22:58
 */
@Service
//@Service(version = "1.0.0",group="dubbo")
public class QrGoodsGroupServiceImpl implements QrGoodsGroupService{
    @Autowired
    private QrGoodsGroupMapper qrGoodsGroupMapper;

    @Autowired
    private QrGoodsGroupMapperView qrGoodsGroupMapperView;
    
    @Autowired
    private DBHelper dbHelper;

    /**
     * 构造查询条件
     */
    private QueryWrapper<QrGoodsGroup> InitWrapper(QrGoodsGroup where){
        QueryWrapper<QrGoodsGroup> whereWrapper = new QueryWrapper<QrGoodsGroup>();
        if(where.getGoods_group_id()!=null){
			whereWrapper.eq("goods_group_id",where.getGoods_group_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getGoods_id()!=null){
			whereWrapper.eq("goods_id",where.getGoods_id());
		}
        if(where.getGroup_id()!=null){
			whereWrapper.eq("group_id",where.getGroup_id());
		}
        return whereWrapper;
    }

    private QueryWrapper<QrGoodsGroupView> InitWrapperView(QrGoodsGroupView where){
        QueryWrapper<QrGoodsGroupView> whereWrapper = new QueryWrapper<QrGoodsGroupView>();
        if(where.getGoods_group_id()!=null){
			whereWrapper.eq("goods_group_id",where.getGoods_group_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getGoods_id()!=null){
			whereWrapper.eq("goods_id",where.getGoods_id());
		}
        if(where.getGroup_id()!=null){
			whereWrapper.eq("group_id",where.getGroup_id());
		}
        return whereWrapper;
    }

    /**
     * 门店商品分组新增
     * @param model 门店商品分组实体
     * @return 影响行数
     */
	@Override
    public Integer add(QrGoodsGroup model){
        return qrGoodsGroupMapper.insert(model);
    }

    /**
     * 门店商品分组修改byid
     * @param model 门店商品分组实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrGoodsGroup model) {
        return qrGoodsGroupMapper.updateById(model);
    }

    /**
     * 门店商品分组修改by条件
     * @param model 门店商品分组实体
     * @param where 门店商品分组条件
     * @return 影响行数
     */
	@Override
    public Integer update(QrGoodsGroup model, Wrapper<QrGoodsGroup> where) {
        return qrGoodsGroupMapper.update(model, where);
    }

    /**
     * 门店商品分组修改by条件-自动封装Wrapper
     * @param model 门店商品分组实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrGoodsGroup model, QrGoodsGroup where) {
        Wrapper<QrGoodsGroup> wrapper = InitWrapper(where);
        return update(model, wrapper);
    }

    /**
     * 门店商品分组修改bySQL *version_id = newVersion where version_id = oldVersion
     * @param fields 修改的数据 col1=xx,col2=yy
     * @param where 参数化条件 col1=#{col1}
     * @param params 条件参数 col1=xx
     * @return 影响行数
     */
	@Override
    public Integer update(Map<String, Object> fields, String where, Map<String, Object> params) {
        return dbHelper.update("qr_goods_group", fields, where, params);
    }

    /**
     * 门店商品分组删除byid
     * @param id 门店商品分组主键
     * @return 影响行数
     */
	@Override
    public Integer del(int id) {
        return qrGoodsGroupMapper.deleteById(id);
    }

    /**
     * 门店商品分组删除by条件
     * @param where 门店商品分组条件
     * @return 影响行数
     */
	@Override
    public Integer del(Wrapper<QrGoodsGroup> where) {
        return qrGoodsGroupMapper.delete(where);
    }

    /**
     * 门店商品分组删除by条件-自动封装Wrapper
     * @param where 门店商品分组条件
     * @return 影响行数
     */
    @Override
    public Integer del(QrGoodsGroup where) { 
        Wrapper<QrGoodsGroup> wrapper = InitWrapper(where);
        return del(wrapper);
    }

    /**
     * 门店商品分组批量删除byid
     * @param ids 门店商品分组主键集合
     * @return 影响行数
     */
	@Override
    public Integer del(List<Integer> ids){
        return qrGoodsGroupMapper.deleteBatchIds(ids);
    }

    /**
     * 门店商品分组批量删除bymap条件
     * @param map 门店商品分组map条件
     * @return 影响行数
     */
	@Override
    public Integer del(Map<String,Object> map){
        return qrGoodsGroupMapper.deleteByMap(map);
    }

    /**
     * 门店商品分组详情byid
     * @param id 门店商品分组主键
     * @return 门店商品分组详情
     */
	@Override
    public QrGoodsGroupView info(int id){
        return qrGoodsGroupMapperView.selectById(id);
    }

    /**
     * 门店商品分组详情by条件
     * @param where 门店商品分组条件
     * @return 门店商品分组详情
     */
	@Override
    public QrGoodsGroupView info(Wrapper<QrGoodsGroupView> where){
        return qrGoodsGroupMapperView.selectOne(where);
    }

    /**
     * 门店商品分组详情by条件-自动封装Wrapper
     * @param where 门店商品分组条件
     * @return 门店商品分组详情
     */
	@Override
    public QrGoodsGroupView info(QrGoodsGroupView where) {
        Wrapper<QrGoodsGroupView> wrapper = InitWrapperView(where);
        return info(wrapper);
    }

    /**
     * 门店商品分组详情bySQL
     * @param columns  列名col1,col2,col3^
     * @param where 条件 col1=#{col1}
     * @param params col1:xx
     * @param mappings col1->col1
     * @return
     */
	@Override
    public QrGoodsGroup info(String columns, String where, Map<String, Object> params, ResultMapping mappings) {
        return dbHelper.selectOne(columns, "qr_goods_group", where, params, QrGoodsGroup.class, mappings);
    }

    /**
     * 门店商品分组批量查询byid
     * @param ids 门店商品分组主键集合
     * @return 门店商品分组列表
     */
	@Override
    public List<QrGoodsGroupView> select(List<Integer> ids){
        return qrGoodsGroupMapperView.selectBatchIds(ids);
    }

    /**
     * 门店商品分组批量查询by条件
     * @param where 门店商品分组条件
     * @return 门店商品分组列表
     */
	@Override
    public List<QrGoodsGroupView> select(Wrapper<QrGoodsGroupView> where){
        return qrGoodsGroupMapperView.selectList(where);
    }

    /**
     * 门店商品分组批量查询by条件-自动封装Wrapper
     * @param where 门店商品分组条件
     * @return 门店商品分组列表
     */
    @Override
    public List<QrGoodsGroupView> select(QrGoodsGroupView where) {
        Wrapper<QrGoodsGroupView> wrapper = InitWrapperView(where);		
        return select(wrapper);
    }

    /**
     * 门店商品分组批量查询bymap条件
     * @param map 门店商品分组map条件
     * @return 门店商品分组列表
     */
	@Override
    public List<QrGoodsGroupView> select(Map<String,Object> map){
        return qrGoodsGroupMapperView.selectByMap(map);
    }

    /**
     * 门店商品分组批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
	@Override
    public IPage<QrGoodsGroupView> select(IPage<QrGoodsGroupView> page, Wrapper<QrGoodsGroupView> where){
        return qrGoodsGroupMapperView.selectPage(page, where);
    }

    /**
     * 门店商品分组批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
    @Override
    public IPage<QrGoodsGroupView> select(IPage<QrGoodsGroupView> page, QrGoodsGroupView where) {
		Wrapper<QrGoodsGroupView> wrapper = InitWrapperView(where);		
        return select(page, wrapper);
    }

    /**
     * 门店商品分组查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(Wrapper<QrGoodsGroupView> where){
        return qrGoodsGroupMapperView.selectCount(where);
    }

    /**
     * 门店商品分组查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(QrGoodsGroupView where){
		Wrapper<QrGoodsGroupView> wrapper = InitWrapperView(where);
        return selectCount(wrapper);
    }

    /**
     * 门店商品分组批量查询bySQL条件分页
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param orderBy 排序字段
     * @param params 参数化 col1=xx
     * @param pageNumber 分页页码
     * @param pageSize 每页行数
     * @param mappings 查询列和实体映射
     * @return 分页之后的数据含总行数
     */
	@Override
    public DataPage<QrGoodsGroupView> select(String columns, String where, String orderBy, Map<String, Object> params, int pageNumber, int pageSize, ResultMapping mappings){
        return dbHelper.select(columns, "qr_goods_group", where, orderBy, params, pageNumber, pageSize, QrGoodsGroupView.class,mappings);
    }

    /**
     * 门店商品分组批量查询bySQL条件
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param params 参数化 col1=xx
     * @param mappings 查询列和实体映射
     * @return 栏目扩展列表
     */
	@Override
    public List<QrGoodsGroupView> select(String columns, String where, Map<String, Object> params, ResultMapping mappings){
        return dbHelper.select(columns,"qr_goods_group",where,params,QrGoodsGroupView.class,mappings);
    }
}